package com.groupbuying.common.baseutils.baseframework4plugins.utils;

import java.text.DecimalFormat;

/**
 * @anthor zmlmagic
 * @date 2018/12/25 5:29 PM
 * @company 蒙泰互联网公司
 * @des 备注说明
 **/

public class DecimalFormatUtils {
    private DecimalFormatUtils() {
    }

    public static String doubleToStr(double d) {
        DecimalFormat df = getDecimalFormat("#.##");
        return df.format(d);
    }

    public static String doubleToStrCustomPattern(double d, String pattern) {
        DecimalFormat df = getDecimalFormat(pattern);
        return df.format(d);
    }

    public static String floatToStr(float f) {
        DecimalFormat df = getDecimalFormat("#.##");
        return df.format((double) f);
    }

    public static String floatToStrCustomPattern(float f, String pattern) {
        DecimalFormat df = getDecimalFormat(pattern);
        return df.format((double) f);
    }

    private static DecimalFormat getDecimalFormat(String pattern) {
        return new DecimalFormat(pattern);
    }

    public static void main(String[] args) {
        //System.out.println(1000000000000L);
    }
}
